package com.sm.li.interceptor;


import com.sm.li.components.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆拦截
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Autowired
    private TokenService tokenService;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       //判断用户是否登陆
        //从头部取出token
        //判断token是否准确
        //1：前缀是不是bearer开头
        //2：能不能解析成功
        return tokenService.checkTokenIsSure(request);
    }
}
